package router

import (
	"oa-system/internal/api/handler"
	// "oa-system/internal/api/middleware"
	"oa-system/internal/config"
	"oa-system/internal/database"
	"oa-system/internal/repository"
	"oa-system/internal/service"

	"github.com/gin-gonic/gin"
)

func RegisterUserRoutes(r *gin.Engine) {
	// 初始化依赖
	userRepo := repository.NewUserRepository(database.DB)
	userService := service.NewUserService(userRepo)
	userHandler := handler.NewUserHandler(userService)

	// API 路由组
	api := r.Group(config.GlobalConfig.App.APIPrefix)

	// 公开路由
	// api.POST("/auth/login", userHandler.Login)
	// api.POST("/auth/register", userHandler.Register)
	// 登录不需要token
	authGroup := api.Group("/auth")
	{
		authGroup.POST("/login", userHandler.Login)
	}

	// 需要认证的路由
	userGroup := api.Group("/users")
	// 开启JWT认证
	// userGroup.Use(middleware.JWTAuthMiddleware())
	{
		userGroup.GET("", userHandler.GetAllUsersWithRoles)
		userGroup.POST("", userHandler.CreateUser)
		userGroup.PUT("/:id", userHandler.UpdateUser)
		userGroup.DELETE("/:id", userHandler.DeleteUser)
	}
}
